<?php

namespace app\apisell\service\Log;

use app\common\utils\Curl;
use app\common\utils\Res;
use think\facade\Db;
use think\facade\Log;

/**
 * 浏览下单记录操作
 * */
class LogNumService
{
    /**
     * 拼团用户浏览记录
     * */
    public static function setBrowseLog($param)
    {
        if (empty($param)) {
            return ['code'=>101, 'msg'=>'参数不得为空'];
        }
        if (empty($param['user_id'])) {
            return ['code'=>102, 'msg'=>'用户ID不得为空'];
        }
        if (empty($param['goods_id'])) {
            return ['code'=>103, 'msg'=>'商品ID不得为空'];
        }
        try {
            $goods = Db::table('xh_sell_goods')
                ->where('id', $param['goods_id'])
                ->where('status', 1)
                ->where('del', 0)
                ->find();
            if (empty($goods)) {
                return ['code'=>104, 'msg'=>'商品不存在，或商品状态不对'];
            }
            if (empty($param['group_no'])) {
                $param['group_no'] = Db::table('xh_sell_groups_team')->where('user_id', $param['user_id'])->where('is_del', 0)->value('group_no');
            }
            $data =  [
                'type' => $goods['property'],  // 类型:1分销;2拼团
                'desc_type' => 1,  // 类型:1浏览;2下单
                'desc_child' => 0,  // 子类型:0默认;1支付;2退款
                'desc_child_desc' => 0,  // 子子类型:0默认;1开团;2参团
                'user_id' => $param['user_id'],
                'goods_id' => $param['goods_id'],
            ];
            if ($goods['property'] == 1) {
                // 分销商品
                if (!empty($param['link_yard'])) {
                    // 分销推广浏览记录
                    $data['link_yard'] = $param['link_yard'];
                } else {
                    // 分销普通浏览记录
                }
            } elseif ($goods['property'] == 2) {
                // 拼团商品
                if (!empty($param['link_yard'])) {
                    // 拼团推广浏览记录
                    $data['link_yard'] = $param['link_yard'];
                    if (!empty($param['group_no'])) {
                        // 拼团团队浏览记录
                        $data['group_no'] = $param['group_no'];
                    }
                } else {
                    // 拼团普通浏览记录
                }
            } else {
                return ['code'=>105, 'msg'=>'商品类型不对'];
            }
            $log = Db::table('xh_sell_num_desc')->where($data)->count();
            if (empty($log)) {
                // 新浏览记录
                $data['person'] = 1;
            } else {
                // 老记录
                $data['person'] = 0;
            }
            $data['time'] = date('Y-m-d H:i:s');
            $addDesc = Db::table('xh_sell_num_desc')->insert($data);
            if (!empty($addDesc)) {
                if ($goods['property'] == 1) {
                    // 分销商品
                    if (!empty($param['link_yard'])) {
                        // 分销推广浏览记录累加
                    } else {
                        // 分销普通浏览记录累加
                    }
                } elseif ($goods['property'] == 2) {
                    // 拼团商品
                    if (!empty($param['link_yard'])) {
                        // 拼团推广浏览记录累加
                        $totalId = Db::table('xh_sell_groups_num')
                            ->where('goods_id', $param['goods_id'])
                            ->where('link_yard', $param['link_yard'])
                            ->where('group_no', null)
                            ->value('id');
                        if (!empty($param['group_no'])) {
                            // 拼团团队浏览记录累加
                            $totalId = Db::table('xh_sell_groups_num')
                                ->where('goods_id', $param['goods_id'])
                                ->where('link_yard', $param['link_yard'])
                                ->where('group_no', $param['group_no'])
                                ->value('id');
                        }
                    } else {
                        // 拼团普通浏览记录累加
                        $totalId = Db::table('xh_sell_groups_num')
                            ->where('goods_id', $param['goods_id'])
                            ->where('link_yard', null)
                            ->where('group_no', null)
                            ->value('id');
                        if (!empty($param['group_no'])) {
                            // 拼团普通团队浏览记录累加
                            $totalId = Db::table('xh_sell_groups_num')
                                ->where('goods_id', $param['goods_id'])
                                ->where('link_yard', null)
                                ->where('group_no', $param['group_no'])
                                ->value('id');
                        }
                    }
                    if (!empty($totalId) && $data['person'] > 0) {
                        // 累加groups_num曝光人数
                        Db::table('xh_sell_groups_num')->where('id', $totalId)->setInc('num');
                    }
                    if (!empty($param['link_yard'])) {
                        $numId = Db::table('xh_sell_num')
                            ->where('type', $goods['property'])
                            ->where('goods_id', $param['goods_id'])
                            ->where('link_yard', $param['link_yard'])
                            ->value('id');
                    } else {
                        $numId = Db::table('xh_sell_num')
                            ->where('type', $goods['property'])
                            ->where('goods_id', $param['goods_id'])
                            ->where('link_yard', null)
                            ->value('id');
                    }
                    if (!empty($numId) && $data['person'] > 0) {
                        // 累加num曝光人数
                        Db::table('xh_sell_num')->where('id', $numId)->setInc('num');
                    }
                }
                // 分销浏览记录累加
            }
        } catch (\Exception $e) {
            Db::table('xh_sell_sync_order_1_log')->insert([
                'info' => $e->getMessage().'行号：'.$e->getLine() . '文件：'.$e->getFile() . '文件栈：' . $e->getTraceAsString(),
                'info_' => '拼团用户浏览记录-失败',
                'create_time' => date('Y-m-d H:i:s')
            ]);
            return ['code'=>106, 'msg'=>'拼团用户浏览记录-失败'];
        }
        return ['code'=>0, 'msg'=>'记录用户浏览成功'];
    }

    /**
     * 下单记录
     */
    public static function setOrderLog($oid)
    {
        if (empty($oid)) {
            return ['code'=>99, 'msg'=>'订单ID不得为空'];
        }
        $param = Db::table('xh_sell_groups_order')->alias('o')
            ->leftJoin('xh_sell_groups_order_goods g', 'o.id = g.order_id')
            ->leftJoin('xh_sell_groups_team t', 'o.id = t.order_id')
            ->leftJoin('xh_sell_groups_link l', 'o.group_link_id = l.id')
            ->where('o.id', $oid)
            ->field('o.id,o.order_no,o.user_id,g.goods_id,t.group_no,l.link_yard,t.is_del')
            ->find();
        if (empty($param)) {
            return ['code'=>101, 'msg'=>'参数不得为空'];
        }
        if (empty($param['user_id'])) {
            return ['code'=>102, 'msg'=>'用户ID不得为空'];
        }
        if (empty($param['goods_id'])) {
            return ['code'=>103, 'msg'=>'商品ID不得为空'];
        }
        try {
            $goods = Db::table('xh_sell_goods')
                ->where('id', $param['goods_id'])
                ->where('status', 1)
                ->where('del', 0)
                ->find();
            if (empty($goods)) {
                return ['code'=>104, 'msg'=>'商品不存在，或商品状态不对'];
            }
            $data =  [
                'type' => $goods['property'],  // 类型:1分销;2拼团
                'desc_type' => 2,  // 类型:1浏览;2下单
                'desc_child' => 0,  // 子类型:0默认;1支付;2退款
                'desc_child_desc' => 0,  // 子子类型:0默认;1开团;2参团
                'user_id' => $param['user_id'],
                'goods_id' => $param['goods_id'],
                'order_no' => $param['order_no'],
            ];
            if ($goods['property'] == 1) {
                // 分销商品
                if (!empty($param['link_yard'])) {
                    // 分销推广下单记录
                    $data['link_yard'] = $param['link_yard'];
                } else {
                    // 分销普通下单记录
                }
            } elseif ($goods['property'] == 2) {
                // 拼团商品
                if (!empty($param['link_yard'])) {
                    // 拼团推广下单记录
                    $data['link_yard'] = $param['link_yard'];
                    if (!empty($param['group_no'])) {
                        // 拼团团队支付记录
                        $data['group_no'] = $param['group_no'];
                        if ($param['is_del'] > 0) {
                            $data['desc_child_desc'] = 1;
                        } else {
                            $data['desc_child_desc'] = 2;
                        }
                    }
                } else {
                    // 拼团普通下单记录
                    if (!empty($param['group_no'])) {
                        // 拼团团队支付记录
                        $data['group_no'] = $param['group_no'];
                        if ($param['is_del'] > 0) {
                            $data['desc_child_desc'] = 1;
                        } else {
                            $data['desc_child_desc'] = 2;
                        }
                    }
                }
            } else {
                return ['code'=>105, 'msg'=>'商品类型不对'];
            }
            $map = $data;
            unset($map['group_no']);
            unset($map['order_no']);
            $log = Db::table('xh_sell_num_desc')->where($map)->count();
            if (empty($log)) {
                // 新下单记录
                $data['person'] = 1;
            } else {
                // 老记录
                $data['person'] = 0;
            }
            $data['time'] = date('Y-m-d H:i:s');
            $addDesc = Db::table('xh_sell_num_desc')->insert($data);
            if (!empty($addDesc)) {
                if ($goods['property'] == 1) {
                    // 分销商品
                    if (!empty($param['link_yard'])) {
                        // 分销推广下单记录累加
                        $totalId = Db::table('xh_sell_groups_num')
                            ->where('goods_id', $param['goods_id'])
                            ->where('link_yard', $param['link_yard'])
                            ->where('group_no', null)
                            ->value('id');
                    } else {
                        // 分销普通下单记录累加
                        $totalId = Db::table('xh_sell_groups_num')
                            ->where('goods_id', $param['goods_id'])
                            ->where('link_yard', null)
                            ->where('group_no', null)
                            ->value('id');
                    }
                } elseif ($goods['property'] == 2) {
                    // 拼团商品
                    if (!empty($param['link_yard']) && !empty($param['group_no'])) {
                        // 拼团推广下单记录累加
                        // 拼团团队下单记录累加
                        $totalId = Db::table('xh_sell_groups_num')
                            ->where('goods_id', $param['goods_id'])
                            ->where('link_yard', $param['link_yard'])
                            ->where('group_no', $param['group_no'])
                            ->value('id');
                    } elseif (!empty($param['group_no'])) {
                        // 拼团普通下单记录累加
                        // 拼团团队下单记录累加
                        $totalId = Db::table('xh_sell_groups_num')
                            ->where('goods_id', $param['goods_id'])
                            ->where('link_yard', null)
                            ->where('group_no', $param['group_no'])
                            ->value('id');
                    } else {
                        return ['code'=>106, 'msg'=>'拼团订单无团号'];
                    }
                    if (empty($totalId)) {
                        $addGroupsNum = [
                            'goods_id' => $param['goods_id'],
                            'link_yard' => $param['link_yard']??null,
                            'group_no' => $param['group_no'],
                        ];
                        $totalId = Db::table('xh_sell_groups_num')->insertGetId($addGroupsNum);
                    }
                    if (!empty($totalId) && $data['person'] > 0) {
                        // 累加groups_num下单人数
                        Db::table('xh_sell_groups_num')->where('id', $totalId)->setInc('place_num');
                    }
                    if (!empty($param['link_yard'])) {
                        $numId = Db::table('xh_sell_num')
                            ->where('type', $goods['property'])
                            ->where('goods_id', $param['goods_id'])
                            ->where('link_yard', $param['link_yard'])
                            ->value('id');
                    } else {
                        $numId = Db::table('xh_sell_num')
                            ->where('type', $goods['property'])
                            ->where('goods_id', $param['goods_id'])
                            ->where('link_yard', null)
                            ->value('id');
                    }
                    if (empty($numId)) {
                        $addNum = [
                            'type' => $goods['property'],
                            'goods_id' => $param['goods_id'],
                            'link_yard' => $param['link_yard']??null,
                        ];
                        $numId = Db::table('xh_sell_num')->insertGetId($addNum);
                    }
                    if (!empty($numId) && $data['person'] > 0) {
                        // 累加num下单人数
                        Db::table('xh_sell_num')->where('id', $numId)->setInc('place_num');
                    }
                }
                // 分销下单记录累加
            }
        } catch (\Exception $e) {
            Db::table('xh_sell_sync_order_1_log')->insert([
                'info' => $e->getMessage().'行号：'.$e->getLine() . '文件：'.$e->getFile() . '文件栈：' . $e->getTraceAsString(),
                'info_' => '拼团用户下单记录-失败',
                'create_time' => date('Y-m-d H:i:s')
            ]);
            return ['code'=>106, 'msg'=>'拼团用户下单记录-失败'];
        }
        return ['code'=>0, 'msg'=>'记录用户下单成功'];
    }

    /**
     * 下单支付记录
     */
    public static function setPayLog($oid)
    {
        if (empty($oid)) {
            return ['code'=>99, 'msg'=>'订单ID不得为空'];
        }
        $param = Db::table('xh_sell_groups_order')->alias('o')
            ->leftJoin('xh_sell_groups_order_goods g', 'o.id = g.order_id')
            ->leftJoin('xh_sell_groups_team t', 'o.id = t.order_id')
            ->leftJoin('xh_sell_groups_link l', 'o.group_link_id = l.id')
            ->where('o.id', $oid)
            ->field('o.id,o.order_no,o.user_id,g.goods_id,t.group_no,l.link_yard,t.group_head')
            ->find();
        if (empty($param)) {
            Db::table('xh_sell_sync_order_1_log')->insert([
                'info' => json_encode(['code'=>101, 'msg'=>'参数不得为空'], JSON_UNESCAPED_UNICODE),
                'info_' => '参数不得为空',
                'create_time' => date('Y-m-d H:i:s')
            ]);
            return ['code'=>101, 'msg'=>'参数不得为空'];
        }
        if (empty($param['user_id'])) {
            Db::table('xh_sell_sync_order_1_log')->insert([
                'info' => json_encode(['code'=>102, 'msg'=>'用户ID不得为空'], JSON_UNESCAPED_UNICODE),
                'info_' => '用户ID不得为空',
                'create_time' => date('Y-m-d H:i:s')
            ]);
            return ['code'=>102, 'msg'=>'用户ID不得为空'];
        }
        if (empty($param['goods_id'])) {
            Db::table('xh_sell_sync_order_1_log')->insert([
                'info' => json_encode(['code'=>103, 'msg'=>'商品ID不得为空'], JSON_UNESCAPED_UNICODE),
                'info_' => '商品ID不得为空',
                'create_time' => date('Y-m-d H:i:s')
            ]);
            return ['code'=>103, 'msg'=>'商品ID不得为空'];
        }
        try {
            $goods = Db::table('xh_sell_goods')
                ->where('id', $param['goods_id'])
                ->where('status', 1)
                ->where('del', 0)
                ->find();
            if (empty($goods)) {
                Db::table('xh_sell_sync_order_1_log')->insert([
                    'info' => json_encode(['code'=>104, 'msg'=>'商品不存在，或商品状态不对'], JSON_UNESCAPED_UNICODE),
                    'info_' => '商品不存在，或商品状态不对',
                    'create_time' => date('Y-m-d H:i:s')
                ]);
                return ['code'=>104, 'msg'=>'商品不存在，或商品状态不对'];
            }
            $data =  [
                'type' => $goods['property'],  // 类型:1分销;2拼团
                'desc_type' => 2,  // 类型:1浏览;2下单
                'desc_child' => 1,  // 子类型:0默认;1支付;2退款
                'desc_child_desc' => 0,  // 子子类型:0默认;1开团;2参团
                'user_id' => $param['user_id'],
                'goods_id' => $param['goods_id'],
                'order_no' => $param['order_no'],
            ];
            if ($goods['property'] == 1) {
                // 分销商品
                if (!empty($param['link_yard'])) {
                    // 分销推广支付记录
                    $data['link_yard'] = $param['link_yard'];
                } else {
                    // 分销普通支付记录
                }
            } elseif ($goods['property'] == 2) {
                // 拼团商品
                if (!empty($param['link_yard'])) {
                    // 拼团推广支付记录
                    $data['link_yard'] = $param['link_yard'];
                    if (!empty($param['group_no'])) {
                        // 拼团团队支付记录
                        $data['group_no'] = $param['group_no'];
                        if ($param['group_head'] == 1) {
                            $data['desc_child_desc'] = 1;
                        } else {
                            $data['desc_child_desc'] = 2;
                        }
                    }
                } else {
                    // 拼团普通支付记录
                    if (!empty($param['group_no'])) {
                        // 拼团团队支付记录
                        $data['group_no'] = $param['group_no'];
                        if ($param['group_head'] == 1) {
                            $data['desc_child_desc'] = 1;
                        } else {
                            $data['desc_child_desc'] = 2;
                        }
                    }
                }
            } else {
                Db::table('xh_sell_sync_order_1_log')->insert([
                    'info' => json_encode(['code'=>105, 'msg'=>'商品类型不对'], JSON_UNESCAPED_UNICODE),
                    'info_' => '商品类型不对',
                    'create_time' => date('Y-m-d H:i:s')
                ]);
                return ['code'=>105, 'msg'=>'商品类型不对'];
            }
            $map = $data;
            unset($map['order_no']);
            $log = Db::table('xh_sell_num_desc')->where($map)->count();
            if (empty($log)) {
                // 新支付记录
                $data['person'] = 1;
            } else {
                // 老记录
                $data['person'] = 0;
            }
            $data['time'] = date('Y-m-d H:i:s');
            $addDesc = Db::table('xh_sell_num_desc')->insert($data);
            if (!empty($addDesc)) {
                if ($goods['property'] == 1) {
                    // 分销商品
                    if (!empty($param['link_yard'])) {
                        // 分销推广支付记录累加
                    } else {
                        // 分销普通支付记录累加
                    }
                } elseif ($goods['property'] == 2) {
                    // 拼团商品
                    if (!empty($param['link_yard']) && !empty($param['group_no'])) {
                        // 拼团推广下单记录累加
                        // 拼团团队下单记录累加
                        $totalId = Db::table('xh_sell_groups_num')
                            ->where('goods_id', $param['goods_id'])
                            ->where('link_yard', $param['link_yard'])
                            ->where('group_no', $param['group_no'])
                            ->value('id');
                    } elseif (!empty($param['group_no'])) {
                        // 拼团普通下单记录累加
                        // 拼团团队下单记录累加
                        $totalId = Db::table('xh_sell_groups_num')
                            ->where('goods_id', $param['goods_id'])
                            ->where('link_yard', null)
                            ->where('group_no', $param['group_no'])
                            ->value('id');
                    } else {
                        Db::table('xh_sell_sync_order_1_log')->insert([
                            'info' => json_encode(['code'=>106, 'msg'=>'拼团订单无团号'], JSON_UNESCAPED_UNICODE),
                            'info_' => '拼团订单无团号',
                            'create_time' => date('Y-m-d H:i:s')
                        ]);
                        return ['code'=>106, 'msg'=>'拼团订单无团号'];
                    }
                    if (!empty($totalId) && $data['person'] > 0) {
                        // 累加groups_num支付人数
                        Db::table('xh_sell_groups_num')->where('id', $totalId)->setInc('payment_num');
                        Db::table('xh_sell_groups_num')->where('id', $totalId)->setInc('groups_order_num');
                        Db::table('xh_sell_groups_num')->where('id', $totalId)->setInc('groups_size');
                    }
                    if (!empty($param['link_yard'])) {
                        $numId = Db::table('xh_sell_num')
                            ->where('type', $goods['property'])
                            ->where('goods_id', $param['goods_id'])
                            ->where('link_yard', $param['link_yard'])
                            ->value('id');
                    } else {
                        $numId = Db::table('xh_sell_num')
                            ->where('type', $goods['property'])
                            ->where('goods_id', $param['goods_id'])
                            ->where('link_yard', null)
                            ->value('id');
                    }
                    if (!empty($numId) && $data['person'] > 0) {
                        // 累加num支付人数
                        Db::table('xh_sell_num')->where('id', $numId)->setInc('payment_num');
                        Db::table('xh_sell_num')->where('id', $numId)->setInc('groups_order_num');
                        Db::table('xh_sell_num')->where('id', $numId)->setInc('groups_size');
                    }
                }
                // 分销支付记录累加
            }
        } catch (\Exception $e) {
            Db::table('xh_sell_sync_order_1_log')->insert([
                'info' => $e->getMessage().'行号：'.$e->getLine() . '文件：'.$e->getFile() . '文件栈：' . $e->getTraceAsString(),
                'info_' => '拼团用户支付记录-失败',
                'create_time' => date('Y-m-d H:i:s')
            ]);
            return ['code'=>106, 'msg'=>'拼团用户支付记录-失败'];
        }
        return ['code'=>0, 'msg'=>'记录用户支付成功'];
    }
    
    /**
     * 分享和海报点击记录
     * */
    public static function setShareLog($param)
    {
        if (empty($param)) {
            return ['code'=>101, 'msg'=>'参数不得为空'];
        }
        if (empty($param['user_id'])) {
            return ['code'=>102, 'msg'=>'用户ID不得为空'];
        }
        if (empty($param['link_yard'])) {
            return ['code'=>103, 'msg'=>'推广标识不得为空'];
        }
        if (empty($param['goods_id'])) {
            $param['goods_id'] = Db::table('xh_sell_groups_link')->where('link_yard', $param['link_yard'])->value('goods_id');
        }
        try {
            $goods = Db::table('xh_sell_goods')
                ->where('id', $param['goods_id'])
                ->where('status', 1)
                ->where('del', 0)
                ->find();
            if (empty($goods)) {
                return ['code'=>104, 'msg'=>'商品不存在，或商品状态不对'];
            }
            if (empty($param['group_no'])) {
                $param['group_no'] = Db::table('xh_sell_groups_team')->where('user_id', $param['user_id'])->where('is_del', 0)->value('group_no');
            }
            $data =  [
                'type' => $goods['property'],  // 类型:1分销;2拼团
                'desc_type' => 3,  // 类型:1浏览;2下单;3分享()
                'desc_child' => $param['type'],  // desc_type为2:子类型:0默认;1支付;2退款。desc_type为3:子类型:0默认;1下载海报;2分享按钮。
                'desc_child_desc' => 0,  // 子子类型:0默认;1开团;2参团
                'user_id' => $param['user_id'],
                'goods_id' => $param['goods_id'],
            ];
            if ($goods['property'] == 1) {
                // 分销商品
                if (!empty($param['link_yard'])) {
                    // 分销推广浏览记录
                    $data['link_yard'] = $param['link_yard'];
                } else {
                    // 分销普通浏览记录
                }
            } elseif ($goods['property'] == 2) {
                // 拼团商品
                if (!empty($param['link_yard'])) {
                    // 拼团推广浏览记录
                    $data['link_yard'] = $param['link_yard'];
                    if (!empty($param['group_no'])) {
                        // 拼团团队浏览记录
                        $data['group_no'] = $param['group_no'];
                    }
                } else {
                    // 拼团普通浏览记录
                }
            } else {
                return ['code'=>105, 'msg'=>'商品类型不对'];
            }
            $log = Db::table('xh_sell_num_desc')->where($data)->count();
            if (empty($log)) {
                // 新浏览记录
                $data['person'] = 1;
            } else {
                // 老记录
                $data['person'] = 0;
            }
            $data['time'] = date('Y-m-d H:i:s');
            $addDesc = Db::table('xh_sell_num_desc')->insert($data);
            if (!empty($addDesc)) {
                if ($goods['property'] == 1) {
                    // 分销商品
                    if (!empty($param['link_yard'])) {
                        // 分销推广浏览记录累加
                    } else {
                        // 分销普通浏览记录累加
                    }
                } elseif ($goods['property'] == 2) {
                    // 拼团商品
                    if (!empty($param['link_yard'])) {
                        // 拼团推广浏览记录累加
                        $totalId = Db::table('xh_sell_groups_num')
                            ->where('goods_id', $param['goods_id'])
                            ->where('link_yard', $param['link_yard'])
                            ->where('group_no', null)
                            ->value('id');
                        if (!empty($param['group_no'])) {
                            // 拼团团队浏览记录累加
                            $totalId = Db::table('xh_sell_groups_num')
                                ->where('goods_id', $param['goods_id'])
                                ->where('link_yard', $param['link_yard'])
                                ->where('group_no', $param['group_no'])
                                ->value('id');
                        }
                    } else {
                        // 拼团普通浏览记录累加
                        $totalId = Db::table('xh_sell_groups_num')
                            ->where('goods_id', $param['goods_id'])
                            ->where('link_yard', null)
                            ->where('group_no', null)
                            ->value('id');
                        if (!empty($param['group_no'])) {
                            // 拼团普通团队浏览记录累加
                            $totalId = Db::table('xh_sell_groups_num')
                                ->where('goods_id', $param['goods_id'])
                                ->where('link_yard', null)
                                ->where('group_no', $param['group_no'])
                                ->value('id');
                        }
                    }
                    if (!empty($totalId) && $data['person'] > 0) {
                        // 累加groups_num曝光人数
                        Db::table('xh_sell_groups_num')->where('id', $totalId)->setInc('groups_share');
                        Db::table('xh_sell_groups_num')->where('id', $totalId)->setInc('groups_download');
                    }
                    if (!empty($param['link_yard'])) {
                        $numId = Db::table('xh_sell_num')
                            ->where('type', $goods['property'])
                            ->where('goods_id', $param['goods_id'])
                            ->where('link_yard', $param['link_yard'])
                            ->value('id');
                    } else {
                        $numId = Db::table('xh_sell_num')
                            ->where('type', $goods['property'])
                            ->where('goods_id', $param['goods_id'])
                            ->where('link_yard', null)
                            ->value('id');
                    }
                    if (!empty($numId) && $data['person'] > 0) {
                        // 累加num曝光人数
                        Db::table('xh_sell_num')->where('id', $numId)->setInc('groups_share');
                        Db::table('xh_sell_num')->where('id', $numId)->setInc('groups_download');
                    }
                }
                // 分销浏览记录累加
            }
        } catch (\Exception $e) {
            Db::table('xh_sell_sync_order_1_log')->insert([
                'info' => $e->getMessage().'行号：'.$e->getLine() . '文件：'.$e->getFile() . '文件栈：' . $e->getTraceAsString(),
                'info_' => '拼团分享和海报点击记录-失败',
                'create_time' => date('Y-m-d H:i:s')
            ]);
            return ['code'=>106, 'msg'=>'拼团分享和海报点击记录-失败'];
        }
        return ['code'=>0, 'msg'=>'记录分享和海报点击成功'];
    }
    
    
}
